/*-------------------------------------------------------------------------
 * CLR版本:     4.0.30319.42000
 * 创建人:      song
 * 创建时间：   2024/4/9 17:56:20
 * 功 能：      Shader GUI Base 绘制ShaderGUI 基类
 *-------------------------------------------------------------------------*/

#if UNITY_EDITOR
namespace SCore.Editor.SShaderDraw
{
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;

    public abstract class SCustomGUIBase : ShaderGUI
    {
        protected List<SComponentGUIBase> coms = new List<SComponentGUIBase>();
        protected Dictionary<string, MaterialProperty> dics = new Dictionary<string, MaterialProperty>();
        private Shader oldShader;

        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            this.dics.Clear();
            foreach (MaterialProperty property in props)
            {
                this.dics.Add(property.name, property);
            }

            this.coms.Clear();
            this.UpdateDics(materialEditor, props);

            EditorGUI.BeginChangeCheck();
            this.coms.ForEach((com) =>
            {
                if (com != null)
                {
                    com.RefreshProperties();
                    com.DrawProperties();
                }
            });

            if (EditorGUI.EndChangeCheck())
            {
                this.coms.ForEach((com) =>
                {
                    if (com != null)
                    {
                        com.Changed();
                    }
                });
            }
        }


        protected abstract void UpdateDics(MaterialEditor materialEditor, MaterialProperty[] props);

        protected SCustomGUIBase()
        {
        }
    }
}
#endif